package com.pension.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pension.model.dao.BoardDao;
import com.pension.model.dao.MemberDao;
import com.pension.model.dto.Board;
import com.pension.model.dto.Member;

@WebServlet("/board/update.action")
public class BoardUpdateServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		//1. Board 객체를 만들고 사용자가 입력한 데이터를 저장
		Board board = new Board();
		board.setBoardNo(
			Integer.parseInt(req.getParameter("boardno")));
		board.setTitle(req.getParameter("title"));
		board.setContent(req.getParameter("content"));

		//2. 데이터베이스에 변경된 내용 적용
		BoardDao dao = new BoardDao();
		dao.updateBoard(board);
		
		//3. 목록 페이지로 이동
		resp.sendRedirect("/pension/board/view.action" +
			"?boardno=" + board.getBoardNo() + 
			"&pageno=" + req.getParameter("pageno"));
		
		
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		req.setCharacterEncoding("utf-8");
		
		doGet(req, resp);
	}
	
}






